import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/clogin'
  },
  // 认证路由 
  {
    path: '/clogin',
    name: 'CLogin',
    component: () => import('@/views/CustomerLogin.vue'),
    meta: { guestOnly: true }
  },
  {
    path: '/cregister',
    name: 'CRegister',
    component: () => import('@/views/CustomerRegister.vue'),
    meta: { guestOnly: true }
  },
  {
    path: '/elogin',
    name: 'ELogin',
    component: () => import('@/views/EmployeeLogin.vue'),
    meta: { guestOnly: true }
  },
  {
    path: '/eregister',
    name: 'ERegister',
    component: () => import('@/views/EmployeeRegister.vue'),
    meta: { guestOnly: true }
  },

  // 客户端路由 
  {
    path: '/c',
    component: () => import('@/layouts/CmainLayout.vue'),
    children: [
      {
        path: '',
        name: 'CPurchase',
        component: () => import('@/views/c/Purchase.vue')
      },
      {
        path: 'purchase',
        name: 'CPurchaseAlt',
        component: () => import('@/views/c/Purchase.vue')
      },
      {
        path: 'ordercreate',
        name: 'COrderCreate',
        component: () => import('@/views/c/OrderCreate.vue')
      },
      {
        path: 'company',
        name: 'CCompany',
        component: () => import('@/views/c/Company.vue')
      },
      {
        path: 'account',
        name: 'CAccount',
        component: () => import('@/views/c/Account.vue')
      },
      {
        path: 'orderlist',
        name: 'COrderList',
        component: () => import('@/views/c/OrderList.vue')
      },

    ]
  },

  // 员工端路由 - e0 (初级员工)
  {
    path: '/e0',
    component: () => import('@/layouts/E0mainLayout.vue'),
    children: [
      {
        path: '',
        name: 'E0Home',
        component: () => import('@/views/e0/OrderCurrent.vue'),
        meta: { title: '首页', shortTitle: "工作台" }
      },
      {
        path: 'ordercurrent',
        name: 'E0Orders',
        component: () => import('@/views/e0/OrderCurrent.vue'),
        meta: { title: '订单管理', shortTitle: "订单" }
      },
      {
        path: 'profile',
        name: 'E0Profile',
        component: () => import('@/views/e0/Profile.vue'),
        meta: { title: '个人资料', shortTitle: "个人" }
      }
    ]
  },

  // 员工端路由 - e1 (财务员工)
  {
    path: '/e1',
    component: () => import('@/layouts/E1mainLayout.vue'),
    children: [
      {
        path: '',
        name: 'E1Home',
        component: () => import('@/views/e1/FinanceReports.vue'),
        meta: { title: '首页', shortTitle: "工作台" }
      },
      {
        path: 'report',
        name: 'E1report',
        component: () => import('@/views/e1/FinanceReports.vue'),
        meta: { title: '财务', shortTitle: "财报" }
      },
      {
        path: 'orders',
        name: 'E1Orders',
        component: () => import('@/views/e1/OrderHistory.vue'),
        meta: { title: '订单管理', shortTitle: "订单" }
      },
      {
        path: 'profile',
        name: 'E1Profile',
        component: () => import('@/views/e1/Profile.vue'),
        meta: { title: '个人资料', shortTitle: "个人" }
      }
    ]
  },

  // 员工端路由 - e2 (高级员工/管理员)
  {
    path: '/e2',
    component: () => import('@/layouts/E2mainLayout.vue'),
    children: [
      {
        path: '',
        name: 'Home',
        component: () => import('@/views/e2/workbench/Home.vue'),
        meta: { title: '首页', shortTitle: "工作台" }
      },
      {
        path: 'quickaction',
        name: 'QuickAction',
        component: () => import('@/views/e2/workbench/QuickAction.vue'),
        meta: { title: '快捷操作', shortTitle: "工作台" }
      },
      // 订单管理 
      // {
      //   path: 'orders/current',
      //   name: 'CurrentOrders',
      //   component: () => import('@/views/e2/order/OrderCurrent.vue'),
      //   meta: { title: '当前订单', shortTitle: "订单" }
      // },
      {
        path: 'orders/list',
        name: 'OrderList',
        component: () => import('@/views/e2/order/OrderList.vue'),
        meta: { title: '订单列表', shortTitle: "订单" }
      },
      {
        path: 'orders/create',
        name: 'OrderCreate',
        component: () => import('@/views/e2/order/OrderCreate.vue'),
        meta: { title: '创建订单', shortTitle: "订单" }
      },
      {
        path: 'orders/stats',
        name: 'OrderStats',
        component: () => import('@/views/e2/order/OrderStats.vue'),
        meta: { title: '订单统计', shortTitle: "订单" }
      },
      // 客户管理 
      {
        path: 'customers/list',
        name: 'CustomerList',
        component: () => import('@/views/e2/customer/CustomerList.vue'),
        meta: { title: '客户列表', shortTitle: "客户" }
      },
      {
        path: 'customers/stats',
        name: 'CustomerStats',
        component: () => import('@/views/e2/customer/CustomerStats.vue'),
        meta: { title: '客户分析', shortTitle: "客户" }
      },
      // 产品管理 
      {
        path: 'products/list',
        name: 'ProductList',
        component: () => import('@/views/e2/product/ProductList.vue'),
        meta: { title: '产品列表', shortTitle: "产品" }
      },
      {
        path: 'products/stats',
        name: 'ProductStats',
        component: () => import('@/views/e2/product/ProductStats.vue'),
        meta: { title: '产品统计', shortTitle: "产品" }
      },
      // 员工管理 
      {
        path: 'employees/list',
        name: 'EmployeeList',
        component: () => import('@/views/e2/employee/EmployeeList.vue'),
        meta: { title: '员工列表', shortTitle: "员工" }
      },
      {
        path: 'employees/task',
        name: 'EmployeeTask',
        component: () => import('@/views/e2/employee/EmployeeTask.vue'),
        meta: { title: '员工列表', shortTitle: "员工" }
      },
      // 财务管理 
      // {
      //   path: 'finance/reports',
      //   name: 'FinanceReports',
      //   component: () => import('@/views/e2/finance/FinanceReports.vue'),
      //   meta: { title: '财务报表', shortTitle: "财务" }
      // },
      // 系统设置 
      {
        path: 'setting/account',
        name: 'Account',
        component: () => import('@/views/e2/setting/Account.vue'),
        meta: { title: '账户', shortTitle: "设置" }
      }
    ]
  },

  // 404处理 
  {
    path: '/:pathMatch(.*)*',
    redirect: '/clogin'
  }
]



// router.beforeEach((to)  => {
//   const authStore = useAuthStore()
//   const isPublicRoute = ['/login', '/register'].includes(to.path) 

//   // 如果访问的是需要认证的页面且未登录 
//   if (!isPublicRoute && !authStore.isAuthenticated)  {
//     return { path: '/login', query: { redirect: to.fullPath  } }
//   }
// })

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router 